package cn.com.jinhao.provider.user.controller;

import cn.com.jinhao.hotline.commons.controller.BaseController;
import cn.com.jinhao.hotline.commons.util.RestResponse;
import cn.com.jinhao.hotline.commons.vo.BaseRequestVO;
import cn.com.jinhao.hotline.commons.vo.business.LinkManInDeptResponseVO;
import cn.com.jinhao.hotline.commons.vo.user.AddressBookRequestVO;
import cn.com.jinhao.provider.user.service.AddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * HotLine
 * <p>Description: 通讯录接口 </p>
 *
 * @author ShaneMew
 * @version 1.0
 * @date 2020/02/21
 * @since 2020/02/21
 */
@RestController
@RequestMapping("addressBook")
@Api(tags = {"通讯录服务"})
public class AddressBookController extends BaseController {
    @Resource
    private AddressBookService addressBookService;

    @ApiOperation(value = "查询部门联系人", notes = "根据部门编码查询部门联系人信息")
    @ApiImplicitParam(name = "deptCode", value = "部门编码", required = true, dataType = "String")
    @GetMapping("/selectByDeptCode")
    public RestResponse<java.util.List<LinkManInDeptResponseVO>> selectByDeptCode(@RequestParam("deptCode") String deptCode) throws Exception {
        return new RestResponse<>(addressBookService.queryByDeptCode(deptCode));
    }

    @ApiOperation(value = "新增部门联系人信息")
    @PostMapping
    public RestResponse<String> add(@ApiParam(name = "addressBookRequestVO", value = "联系人信息") @Validated(BaseRequestVO.Create.class) @RequestBody AddressBookRequestVO addressBookRequestVO, BindingResult result) throws Exception {
        validate(result);
        addressBookService.add(addressBookRequestVO);
        return new RestResponse<>(null);
    }

    @ApiOperation(value = "更新部门联系人信息")
    @PutMapping
    public RestResponse<String> update(@ApiParam(name = "addressBookRequestVO", value = "联系人信息") @Validated(BaseRequestVO.Update.class) @RequestBody AddressBookRequestVO addressBookRequestVO, BindingResult result) throws Exception {
        validate(result);
        addressBookService.update(addressBookRequestVO);
        return new RestResponse<>(null);
    }

    @ApiOperation(value = "删除部门联系人信息")
    @DeleteMapping
    public RestResponse<String> delete(@ApiParam(name = "id", value = "主键ID") @RequestParam String id) throws Exception {
        addressBookService.delete(id);
        return new RestResponse<>(null);
    }
}
